package com.tianyadu.mmall.controller.async;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 模拟消息队列信息
 *
 * @author xueyj
 * @date 2019-09-29 14:15
 */
@Component
@Slf4j
public class MockQueue {
    /**
     * 创建新订单请求信息
     */
    private String placeOrder;
    /**
     * 创建新订单响应信息
     */
    private String completeOrder;

    public String getPlaceOrder() {
        return placeOrder;
    }

    /**
     * 模拟下单请求，返回下单结果信息
     *
     * @param placeOrder 订单信息
     * @author xueyj
     * @date 2019/9/29-15:58
     */
    public void setPlaceOrder(String placeOrder) throws Exception {
        //  模拟订单处理服务器线程处理下单请求
        new Thread(() -> {
            log.info("接到下单请求,【{}】 ", placeOrder);
            try {
                //  处理下单业务逻辑
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //  将下单结果信息返回至订单响应结果
            this.completeOrder = placeOrder;
            log.info("下单请求处理完毕,【{}】 ", placeOrder);
        }).start();
    }

    public String getCompleteOrder() {
        return completeOrder;
    }

    public void setCompleteOrder(String completeOrder) {
        this.completeOrder = completeOrder;
    }

}